package com.tskj.mh.savefoodorder.Interceptor.entity;

import org.springframework.stereotype.Component;

import java.util.HashSet;

/**
 * @notes:
 * @program: easystar2018_ss_v2.0
 * @author: JRX
 * @create: 2019-08-13 13:56
 * 查询接名口是否存在
 **/
@Component
public class FilterInterfaceList {

    public boolean sysFilter(String sysFilterPath) {
        HashSet hashSet = sysFilterSet();
        boolean flag = hashSet.add(sysFilterPath);
        //System.err.println(flag);
        return flag;
    }

    public boolean logFilter(String sysFilterPath) {
        HashSet hashSet = logFilterSet();
        boolean flag = hashSet.add(sysFilterPath);
        //System.err.println(flag);
        return flag;
    }

    public boolean notFilter(String sysFilterPath) {
        HashSet hashSet = notFilterSet();
        boolean flag = hashSet.add(sysFilterPath);
        //System.err.println(flag);
        return flag;
    }

    public static void main(String[] args) {
        FilterInterfaceList f = new FilterInterfaceList();
        //boolean b = f.sysFilter("usermanager.do");
        System.err.println(f.propPower("2", "SysLogs.do"));

    }

    public HashSet sysFilterSet() {
        //感觉后面多了还是数据库中来存查询比较好
        HashSet hs = new HashSet();
//        hs.add("/login.do");
        return hs;
    }

    public HashSet logFilterSet() {
        HashSet hs = new HashSet();
        hs.add("/SysLogs.do");
        //用方法二才增加logout，方法一请注释掉否则会退出出错
        hs.add("/Logout.do");
        hs.add("/FuzzySearchSyslogs.do");

        return hs;
    }

    //方法一
    public boolean FirstpropPower(String prop, String requestURI) {
        //日志中存在 判定prop是否正确
        if (!logFilter(requestURI)) {
            if (prop.equals("1")) {
                return true;
            } else {
                return false;
            }
        }
        if (!sysFilter(requestURI)) {
            if (prop.equals("2")) {
                return true;
            } else {
                return false;
            }
        }
        return true;
    }

    //方法二
    public boolean propPower(String prop, String requestURI) {
        //System.err.println(prop);
        switch (prop) {
            case "0"://操作员
                if (sysFilter(requestURI) && logFilter(requestURI)) {
                    return true;
                } else {
                    if (requestURI.equals("/Logout.do")) {
                        return true;
                    }
                    return false;
                }
            case "1"://日志审计
                if (!logFilter(requestURI)) {
                    return true;
                } else {
                    return false;
                }
            case "2"://系统管理员
                if (!sysFilter(requestURI)) {
                    return true;
                } else {
                    return false;
                }
            default:
                return false;

        }

    }

    public HashSet notFilterSet() {
        HashSet hs = new HashSet();
        hs.add("/login.do");
        hs.add("/mobile/login.do");
        return hs;
    }


}
